package vn.sunnet.backviet01.game.coloa.animated.skill;

import org.anddev.andengine.entity.modifier.MoveYModifier;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.BaseSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class SkillToaDiaChan extends AnimatedSkill{
	private static final long[] duration = {250, 150, 150, 150, 150, 150, 150, 150};
	
	
	private boolean isTrans = false;
	private boolean isAttak = false;
	private boolean isCheck = false;
	
	private float damage = 0;
	private float useMana = 0;
	
	private final int name;
	private long start = 0;
	
	public SkillToaDiaChan(int name, float pX, float pY,
			TiledTextureRegion pTiledTextureRegion, TiledTextureRegion pChildTexture) {
		super(name, pX, pY, pTiledTextureRegion);
		this.setPosition(pX - 110, pY - 200);
		this.name = name;
		AnimatedSprite mChild = new AnimatedSprite(85, -this.getY() - 460, pChildTexture);
		long[] durationChild = {80, 120};
		mChild.animate(durationChild);
		this.animate(duration);
		this.attachChild(mChild);
		MoveYModifier modifier = new MoveYModifier(0.1f, mChild.getY(), -280);
		mChild.registerEntityModifier(modifier);
		modifier.setRemoveWhenFinished(true);
		start = System.currentTimeMillis();
	}

	public void onManagedUpdate(float pSecondsElapsed) {
		if (this.getCurrentTileIndex() > 1 && this.getCurrentTileIndex() < 7 ) {
			if (!isCheck) {
				isAttak = true;
				isCheck = true;
				this.getChild(0).setVisible(false);
			}
			if (!isTrans) {
				isTrans = true;
				this.setZIndex(0);
			}
		} 
		
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	@Override
	public boolean attack(float pX, float pY) {
		float xOffset = this.xGoal - pX;
		float yOffset = this.yGoal - pY;
		
		float offset = (float)(Math.sqrt(xOffset * xOffset + yOffset * yOffset));
		
		if (offset < 120 + mLevel * 10)
			return true;
		
		return false;
	}

	@Override
	public void complete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getName() {
		// TODO Auto-generated method stub
		return name;
	}

	@Override
	public boolean isAttack() {
		// TODO Auto-generated method stub
		return isAttak;
	}

	@Override
	public void stopInfluence() {
		isAttak = false;
		
	}

	@Override
	public float getDamge() {
		// TODO Auto-generated method stub
		return damage;
	}

	@Override
	public void setDamage(float damage) {
		this.damage = damage;
		
	}

	@Override
	public float useMana() {
		// TODO Auto-generated method stub
		return this.useMana;
	}

	@Override
	public void setMana(float mana) {
		useMana = mana;
	}

	@Override
	public long getStart() {
		// TODO Auto-generated method stub
		return start;
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public BaseSprite returnSeft() {
		// TODO Auto-generated method stub
		return this;
	}

}
